<template>
  <div class="background-container" style="background-image: url('/img/1.jpg');">
    <el-container>
      <el-header>
        <el-row style="color:rgb(223, 205, 186);font-weight:bold;font-size: 30px; line-height: 86px">
          <el-col :span="5"></el-col>
          <el-col :span="1">
            <img src="/img/logo.webp" style="width: 50px; margin-top: 10px">
          </el-col>
          <el-col :span="1">
            <img src="/img/verticalLine.png" style="height: 80px;">
          </el-col>
          <el-col :span="17">
            <span class="title-text">欢迎登录月子中心平台</span>
          </el-col>
        </el-row>
      </el-header>
      <el-main>
        <el-row>
          <el-col :span="16"></el-col>
          <el-col :span="8">
            <el-card style="margin-top: 100px;">

              <el-form label-position="top">
                <h3 style="text-align: center">月子中心登录平台</h3>
                <el-row>
                  <el-col >
                    <el-form-item label="用户名">
                      <el-input placeholder="请输入用户名" v-model="user.username"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col >
                    <el-form-item label="密码">
                      <el-input placeholder="请输入密码" v-model="user.password"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
              <el-button type="primary" style="width: 100%; margin-top: 20px;" @click="login">登录</el-button>
            </el-card>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
  </div>
</template>


<script setup>

  import {ref} from "vue";
  import axios from "axios";
  import qs from "qs";
  import {ElMessage} from "element-plus";
  import router from "@/router";

  const user = ref({
    username: '',
    password: '',
    status:''
  })

  const login = () => {
    console.log(user.value)
    let data = qs.stringify(user.value)
    axios.get(BASE_URL+'/user/customers/search'+data).then((response) => {
      if (response.data.code === 2000) {
        ElMessage.success('登录成功')
        if (response.data.status === 10) {
          router.push('/home')
        }
        if (response.data.status === 20) {
          router.push('/user')
        }
        if (response.data.status === 30) {
          router.push('/staff')
        }
        localStorage.setItem('user',JSON.stringify(response.data.data));
      }else {
        user.value = {}
        ElMessage.error('用户名或密码错误')
      }
    })
  }
</script>



<style scoped>
.background-container {
  background-size: cover; /* 使图片覆盖整个容器 */
  width: 100%; /* 设置宽度 */
  height: 100vh; /* 设置高度 */
  overflow: hidden; /* 隐藏溢出内容 */
}
</style>